﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;
using System.Media;
namespace TestApp
{
    public partial class Form4 : Form
    {
        public Form4()
        {
            InitializeComponent();
        }

        private void Form4_Load(object sender, EventArgs e)
        {
            txt = richTextBox1.Text;
            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            
           
        }
        // for storing the hold text in richtexbox 1
        private string txt = "";
        // for counting the time you write
        private long keyCounter = 0;
        // number of error
        private long NumError = 0;
        // for current index
        private int CurIndex = 0;
        private void richTextBox2_KeyPress(object sender, KeyPressEventArgs e)
        {
            char ch = e.KeyChar;
            if (CurIndex == txt.Length-1)
            {
                MessageBox.Show("It's Over!");
                richTextBox2.ReadOnly = true;
            }
            if (txt[CurIndex] == ch)
            {
                richTextBox1.Select(CurIndex, 1);
                richTextBox1.SelectionColor = Color.Red;
                CurIndex++;
            }
            else if (txt[CurIndex]=='\n')
            {
                
                CurIndex++;
            }
            else
            {
                NumError++;
            }
            keyCounter++;
            label1.Text = "Error: " + NumError.ToString();
            label2.Text = "Try: " + keyCounter.ToString();
        }
    }
}
